# Maintainer: Daniel Isaksen <d@duniel.no>
pkgname=rebar3
pkgver=3.11.1
pkgrel=1
pkgdesc="erlang build tool that makes it easy to compile and test erlang applications and releases"
url="http://www.rebar3.org/"
arch="noarch !armv7 !mips !mips64" # blocked by erlang
license="Apache-2.0"
depends="erlang erlang-compiler"
makedepends="erlang-dev erlang-ssl erlang-eunit erlang-sasl erlang-dialyzer erlang-hipe"
checkdepends="erlang-common-test erlang-tools erlang-snmp erlang-edoc erlang-erts"
install=""
subpackages=""
_bbmustache_ver="1.6.1"
_certifi_ver="2.5.1"
_cf_ver="0.2.2"
_cth_readable_ver="1.4.4"
_erlware_commons_ver="1.3.1"
_eunit_formatters_ver="0.5.0"
_getopt_ver="1.0.1"
_providers_ver="1.8.1"
_relx_ver="3.32.1"
_ssl_verify_fun_ver="1.1.5"
_meck_ver="0.8.13"
source="rebar3-$pkgver.tar.gz::https://github.com/erlang/rebar3/archive/$pkgver.tar.gz
	https://repo.hex.pm/tarballs/bbmustache-$_bbmustache_ver.tar
	https://repo.hex.pm/tarballs/certifi-$_certifi_ver.tar
	https://repo.hex.pm/tarballs/cf-$_cf_ver.tar
	https://repo.hex.pm/tarballs/cth_readable-$_cth_readable_ver.tar
	https://repo.hex.pm/tarballs/erlware_commons-$_erlware_commons_ver.tar
	https://repo.hex.pm/tarballs/eunit_formatters-$_eunit_formatters_ver.tar
	https://repo.hex.pm/tarballs/getopt-$_getopt_ver.tar
	https://repo.hex.pm/tarballs/providers-$_providers_ver.tar
	https://repo.hex.pm/tarballs/relx-$_relx_ver.tar
	https://repo.hex.pm/tarballs/ssl_verify_fun-$_ssl_verify_fun_ver.tar
	https://repo.hex.pm/tarballs/meck-$_meck_ver.tar
	"
builddir="$srcdir/rebar3-$pkgver"

# XXX: rebar3 eunit reports no tests, so I guess there is none.  but I'm not sure.
# XXX: rebar3 bootstrap tries to download a package index (but all of the dependencies are predownloaded),
#      which means we need networking enabled

#options="net !check"

_prepare_subpkg() {
	msg "unpacking $1 $2 to _build/default/lib"

	mkdir -p "$builddir/_build/default/lib/$1"

	cd "$builddir/_build/default/lib/$1"
	tar xf "$srcdir"/"$1"-"$2".tar
	tar zxf contents.tar.gz
	rm contents.tar.gz
	cd "$builddir"
}

prepare() {
	default_prepare

	_prepare_subpkg bbmustache		$_bbmustache_ver
	_prepare_subpkg certifi			$_certifi_ver
	_prepare_subpkg cf			$_cf_ver
	_prepare_subpkg cth_readable		$_cth_readable_ver
	_prepare_subpkg erlware_commons		$_erlware_commons_ver
	_prepare_subpkg eunit_formatters	$_eunit_formatters_ver
	_prepare_subpkg getopt			$_getopt_ver
	_prepare_subpkg providers		$_providers_ver
	_prepare_subpkg relx			$_relx_ver
	_prepare_subpkg ssl_verify_fun		$_ssl_verify_fun_ver
	_prepare_subpkg meck			$_meck_ver

	ln -sf default "$builddir"/_build/bootstrap
}

build() {
	# DEBUG=1 gives us verbose build output
	# we use /tmp/rebar-build as home dir because rebar3 bootstrap downloads a package index and it cannot be disabled

	mkdir -p /tmp/rebar-build
	HOME=/tmp/rebar-build ./bootstrap

	# clean up
	#rm -rf /tmp/rebar-build
}

check() {
	HOME=/tmp/rebar-build ./rebar3 ct

	# cleanup
	rm -rf /tmp/rebar-build
}

package() {
	cd "$builddir"
	install -D -m0755 rebar3 "$pkgdir"/usr/bin/rebar3
}

sha512sums="749368c8c19641d0c1083f1750438cfc5f1c75e284bd74b4f8ae368103e79a376f4bd91e85db35e1619116cd2f3b1a8dc2d3d89db19da8f4440e0b58d3c0a37c  rebar3-3.11.1.tar.gz
7da99c76c5bb5b7cdc213784184c06d8be093a53c2d1da45d82677a3b18672c9368c4dac39797dee50c83cae7be4d06979d5ad2bee6b9d9d7f83fb56ebb8b032  bbmustache-1.6.1.tar
478126f314065d6d91f6854b9565461ca0c3d31265b952bbe6eb3643e861ee1faeba388c2d356d3595381aa3a5d5871c7c98cb85d8e6ab614917eb5c8be9082a  certifi-2.5.1.tar
0afbe335c6170f1f4efa6fb22111d8698abc288b1cc125fb69653958df1dbdb1a936f927309b460dc6cfa1fc2b15c82838b8935d5fa8e28dab1c050295608698  cf-0.2.2.tar
2036b947d33037afd2d043447bd533e207490c290ef1bd0115660c76824dbd95ce03c56bb4b89377a82bab25dab1bb19e28fc42d3f56064ea261a57b7f9f183e  cth_readable-1.4.4.tar
1f9e7617b88ec7cae6e83da1a60a2d22ce3325b6425cd284c3ec3dd0de49a26220b868ea60a937758dd65d7ea137819e314504a98ced99fc2617056ada4d2fa0  erlware_commons-1.3.1.tar
e8692ff35f979dfaf99ccac58014429d300a71ff76f2ce945814a0d4d9431821f04f988dc0271271858a37e6903a73b4dd9ae3abf215333f3135fa883ec07022  eunit_formatters-0.5.0.tar
859642dc26c42414474fa8af8a32fed827b0773ac6d6eb51ec19c291672408e71619ad2bb0c7f08d84ff591b33a655a7e0b6241b94372e9cc816a648ee6cdaf6  getopt-1.0.1.tar
b1db18264c98717849ed521f8eb1ef0f112ea5e602bcd529fd97996120640c7567097174180673ba166d4c408496ce63c351ce70a3f385ed1ae7d1e444e2587a  providers-1.8.1.tar
2bcc9a8a12cc1fbca3c195cc61d60acda98b49df72a068dcc8bed3fa645ad76f3d008f31f914bdb5ec48fc372b6196abeadf8dddf188b5c91a314f1852aa9d27  relx-3.32.1.tar
9beef3fb7b1aa2e40202d321442159a502a6efdcac3d15397c0dfffef633a1f5af8baa006eb4437d14620ffc2e23018111f1626d2f34a63e804cd8e11fe17f71  ssl_verify_fun-1.1.5.tar
adcfd3fdf69d4926dc1d9c2f0b477c8977bddba8b8ffdbfedcf1b5dc3c1af47b39b1c6263c922a43efede90f145f009d71b27178597320522960c5ebbd84a15a  meck-0.8.13.tar"
